package com.cx.mall.user.controller;

import com.cx.mall.common.utils.ResponseVO;
import com.cx.mall.common.model.user.UserReceiveAddress;
import com.cx.mall.common.model.user.UserReceiveAddressDTO;
import com.cx.mall.user.service.IUserReceiveAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户收货地址表 前端控制器
 * </p>
 *
 * @author lyt
 * @since 2025-07-08
 */
@RestController
@RequestMapping("/user/address")
public class UserReceiveAddressController {
    @Autowired
    private IUserReceiveAddressService userReceiveAddressService;

    @RequestMapping("/save")
    public ResponseVO save(@RequestBody UserReceiveAddress userReceiveAddress){
        //调用业务层
        userReceiveAddressService.saveOrUpdate(userReceiveAddress);
        return ResponseVO.success();
    }

    @GetMapping("/{id}")
    public ResponseVO listById(@PathVariable("id") Long userId){
        //调用业务层
        List<UserReceiveAddressDTO> list = userReceiveAddressService.listByUserId(userId);
        return ResponseVO.success(list);
    }
}
